<!--
 * @Author: your name
 * @Date: 2022-03-20 12:18:12
 * @LastEditTime: 2022-03-20 12:31:59
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \算法测试\day0906\周赛6029.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
         *  DFS 回溯
 * @param {number} numArrows
 * @param {number[]} aliceArrows
 * @return {number[]}
 */
        var maximumBobPoints = function (numArrows, aliceArrows) {
            // 最大分数
            let maxPoint = 0;
            let ans = [];
            // 状态压缩
            for (let i = 0; i < 1 << 12; i++) {
                let res = 0;
                let arrows = numArrows;
                let arr = [];
                for (let j = 0; j < 12; j++) {
                    if (i >> j & 1 === 1) {
                        if (arrows - aliceArrows[j] > 0) {
                            arrows -= aliceArrows[j] + 1;
                            res += j;
                        }
                        arr.push(aliceArrows[j] + 1);
                    } else {
                        arr.push(0);
                    }
                }
                if (res > maxPoint) {
                    maxPoint = res;
                    // 剩下的箭给0
                    if (arrows > 0) {
                        arr[0] = arrows;
                    }
                    ans = arr;
                }
            }
            return ans;
        };
        maximumBobPoints(9, [1, 1, 0, 1, 0, 0, 2, 1, 0, 1, 2, 0])
    </script>
</body>

</html>